<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>reset方法????????????</title>
		<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css" />
		<script src="js/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/Underscore-1.8.3min.js"></script>
		<script src="js/backbone.js"></script>
		<script type="text/javascript">
		</script>
	</head> 
	<body>
		<script type="text/javascript">
			var Animal = Backbone.Model.extend({
				initialize: function() {
					console.log();
				},
				defaults: function() {
					name: "宠物"
				}
			});
			var AnimalList = Backbone.Collection.extend({
				model: Animal
			});
			var cat1 = new Animal({
				name: "黑喵"
			});
			var cat2 = new Animal({
				name: "黄喵"
			});
			var cat3 = new Animal({
				name: "白喵"
			});
			animallist = new AnimalList;
			animallist.add(cat1);
			animallist.add(cat2);
			animallist.add(cat3); 
			
			animallist.each(function(cat){
				console.log(cat.get("name"));
			});
			 
			 //
			 var showAllcat=function(){
			 	animallist.each(function(animal){
			 		document.writeln(animal.get("name"));
			 	});
			 }
			 animallist.bind("reset",showAllcat);
			 animallist.url="";
			 animallist.fetch({
				success:function(collection,response,options){
					collection.each(function(animal){
						console.log(animal.get('name'));
					});
				},
				error:function(){
					console.log("又碰到跨域问题了");
				}
			})
		</script>
		
	</body>
</html>